/* MovementRule.java
 * 
 * Alfred Olschnoegger
 * 29.06.2008
 */

package domain.objectRules;

import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import domain.GameObject;
import domain.Hunter;
import domain.game.Game;
import domain.location.Position;

/**
 * TODO description
 * 
 * @date 29.06.2008
 * @author Alfred Olschnoegger
 */

public class MovementRule extends ObjectRule {

	@Override
	public void use(GameObject obj, Game game) {
		Collection<Hunter> hunters = game.getValidHunterNames();
		Set<Position> positions = new HashSet<Position>();
		for (Hunter hunter : hunters) {
			positions.add(hunter.getPos());
		}
		
		Random rand = new Random();
		
		int xMove = rand.nextInt(3) - 1;
		int yMove = rand.nextInt(3) - 1;
		
		
		game.getArea().move(obj.getPos(), xMove, yMove);
		if(positions.contains(obj.getPos()))
			game.getArea().move(obj.getPos(), xMove * -2, yMove * -2);
	}

}

// end of MovementRule.java
